package com.rpframework.module.common.bottom.service.impl;


import com.rpframework.core.utils.Md5Utils;
import com.rpframework.module.common.bottom.entity.AdminUser;
import com.rpframework.module.common.bottom.mapper.AdminUserMapper;
import com.rpframework.module.common.bottom.service.AdminUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * 默认实现
 * Created by jump on 2016/7/4.
 */
@Service
public class AdminUserServiceImpl extends BaseServiceImpl<AdminUser> implements AdminUserService {

    @Autowired
    public AdminUserServiceImpl(AdminUserMapper mapper) {
        super(mapper);
    }

    @Override
    public Example getExample() {
        return new Example(AdminUser.class);
    }

    @Override
    public int updateByPrimaryKey(AdminUser record) {
        updateInit(record);
        return super.updateByPrimaryKey(record);
    }

    @Override
    public int updateByPrimaryKeySelective(AdminUser record) {
        updateInit(record);
        return super.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByExample(AdminUser record, Object example) {
        updateInit(record);
        return super.updateByExample(record, example);
    }

    @Override
    public int updateByExampleSelective(AdminUser record, Object example) {
        updateInit(record);
        return super.updateByExampleSelective(record, example);
    }

    @Override
    public int updates(List<AdminUser> AdminUsers) {
        AdminUsers.forEach(this::updateInit);
        return super.updates(AdminUsers);
    }

    /**
     * 修改实体类操作初始化
     *
     * @param entity 实体类
     */
    private void updateInit(AdminUser entity) {
        if (entity.getPassword() != null) {
            entity.setPassword(Md5Utils.md5(entity.getPassword()));
        }
    }

}
